﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using negocios;
using objetos;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Data;

namespace softsales.pagina.cadastro
{
    /// <summary>
    /// Summary description for cadastro
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class cadastro : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public string SelecionarPorId(string id)
        {
            BLL_TB_CADASTRO b_tb_cadastro = new BLL_TB_CADASTRO();
            OBJ_TB_CADASTRO o_tb_cadastro = new OBJ_TB_CADASTRO();

            BLL_TB_ENDERECO_CADASTRO b_tb_endereco_cadastro = new BLL_TB_ENDERECO_CADASTRO();
            try
            {

              

                o_tb_cadastro = b_tb_cadastro.SelecionarObjetoPorId(Convert.ToInt32(id));              
                

                if (o_tb_cadastro != null)
                {
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    return js.Serialize(o_tb_cadastro);
                }
                else
                {
                    return "null";
                }

            }
            catch (Exception ex)
            {

                return ex.Message;
            }

        }

        [WebMethod]
        public string ExisteCPF(string cpf)
        {
            try
            {

                BLL_TB_CADASTRO b_tb_cadastro = new BLL_TB_CADASTRO();
                OBJ_TB_CADASTRO o_tb_cadastro = new OBJ_TB_CADASTRO();
                JavaScriptSerializer js = new JavaScriptSerializer();
                if (b_tb_cadastro.SelecionarLista(string.Format("cnpj_cpf = '{0}'", cpf), "").Count > 0)
                {
                    return js.Serialize("1");
                }
                else
                {
                    return js.Serialize("0");
                }
              

            }
            catch (Exception ex)
            {

                return ex.Message;
            }

        }

        [WebMethod]
        public string ExisteCNPJ(string cnpj)
        {
            try
            {

                BLL_TB_CADASTRO b_tb_cadastro = new BLL_TB_CADASTRO();
                OBJ_TB_CADASTRO o_tb_cadastro = new OBJ_TB_CADASTRO();
                JavaScriptSerializer js = new JavaScriptSerializer();
                if (b_tb_cadastro.SelecionarLista(string.Format("cnpj_cpf = '{0}'", cnpj), "").Count > 0)
                {
                    return js.Serialize("1");
                }
                else
                {
                    return js.Serialize("0");
                }


            }
            catch (Exception ex)
            {

                return ex.Message;
            }

        }
    }
}
